<?php
/**
 * Egany_Metabox_Validation_Period
 *
 * Author URI: http://www.facebook.com/
 * @author 		PhongND
 * @category 	Admin
 * @package 	egany_discount_offer
 * @version     1.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}



class Egany_Metabox_Validation_Period {


	/**
	 * Output the metabox 
	 */
	public static function output( $post ) {
		// global $theorder;

		
		// $args = array(
			// 'post_type'        => 'periodic_discount',
			// 'post_status'      => 'any',
			// 'orderby'          => 'post_date', // post_date / date
			// 'order'            => 'desc',
		// );
		// $arrPosts = get_posts( $args );
		
		// if (count($arrPosts) > 0) 
		// {
			// $strID = $arrPosts[0]->ID;
			// var_dump('Last ID: '. $strID);
			// var_dump(get_post_meta( $strID, 'validation_no', true ));
		// }
		// else
			// var_dump('NONE');
		?>
		<style type="text/css">
		
			/*  #edit-slug-box, #minor-publishing-actions, #major-publishing-actions, #minor-publishing-actions, #visibility, #submitdiv */
			
			#post-body-content, #titlediv { display:none }
		</style>
		
		<div class="panel-wrap periodic_discount_tabs">
		
			<div id="tab_general_periodic_discount_data" class="panel woocommerce_options_panel" style="">
				<?php 
					//echo '<div class="options_group">';
					
					woocommerce_wp_text_input( array( 'id' => 'validation_no', 'label' => __( 'No', 'EGANY' ), 'placeholder' => __('Validation No', 'placeholder', 'EGANY' ), 'description' => __( 'Validation No.', 'EGANY' ), 'type' => 'texr', 'desc_tip' => true, 'class' => 'short' ) );
					woocommerce_wp_text_input( array( 'id' => 'description', 'label' => __( 'Description', 'EGANY' ), 'placeholder' => __('Description', 'placeholder', 'EGANY' ), 'description' => __( 'Description.', 'EGANY' ), 'type' => 'text', 'desc_tip' => true, 'class' => 'short') );
					
					// Starting Date
					woocommerce_wp_text_input( array( 'id' => 'starting_date', 'label' => __( 'Starting Date', 'EGANY' ), 'description' => '', 'placeholder' => __( 'YYYY-MM-DD', 'placeholder', 'EGANY' ), 'class' => 'date-picker', 'custom_attributes' => array( 'pattern' => "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" ) ) );
					
					// Ending Date
					woocommerce_wp_text_input( array( 'id' => 'ending_date', 'label' => __( 'Ending Date', 'EGANY' ), 'description' => '', 'placeholder' => __( 'YYYY-MM-DD', 'placeholder', 'EGANY' ), 'class' => 'date-picker', 'custom_attributes' => array( 'pattern' => "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" ) ) );
					
					//echo '</div>';
					?>
				
			</div>
			
		</div>
		
		
		<script type="text/javascript">
			//ok, displaying div under a tab view.
			//asd==$, also ok!
			// jQuery(function($) {
				// $( ".periodic_discount_tabs" ).tabs();
			// });
		</script>
		
		<?php
	}

	/**
	 * Save meta box data
	 */
	public static function save( $post_id, $post ) {
		global $wpdb;
		
		$validation_no  	=  $_POST['validation_no'];
		$description   	=  $_POST['description'];
		$starting_date   	= $_POST['starting_date'];
		$ending_date         = $_POST['ending_date'];
		
		// Update meta
		update_post_meta( $post_id, 'validation_no', $validation_no);
		update_post_meta( $post_id, 'description', $description);
		update_post_meta( $post_id, 'starting_date', $starting_date);
		update_post_meta( $post_id, 'ending_date', $ending_date);
		
		return $post_id;
	}

}


